<section id="container">
	<!--main content start-->
	<section id="main-content">
		<section class="wrapper">
			<!--state overview end-->
			<div class="row">
				<div class="col-lg-12">
					<div class="alert alert-block alert-danger fade in">
						<button data-dismiss="alert" class="close close-sm" type="button">
							<i class="icon-remove"></i>
						</button>
						<strong>友情提示：</strong><br />
						1、每月最后一个工作日需要相关人员完成用服人员、开发人员的成本确认，完成成本的设定。每月月末25号人事控制月底入职电子流，每月最后倒数第三个工作日相关人员完成用服人员归集并提交确认。每月最后倒数第二个工作日前相关人员完成开发人员归集和各部门确认，并提交确认。每月倒数第二个工作日相关人员完成成本设定；<br />
						2、 一旦用服人员或者研发人员的成本归集提交确认后，本月就不能再修改。系统自动把未分配人员设定为销管成本；<br />
						3、只有投入到客服的人员才可以填写客服工时。
					</div>
					<section class="panel" id="stepCmt" style="display: none">
						<header class="panel-heading">
							成员类型变更<span style="color: red;font-weight: bold">（人员成本若发生变化，请务必和相关部门确认之后再提交，一旦提交系统自动完成相关计算和归档，
                    无法回退处理！）</span>
						</header>
						<div class="panel-body">
							<div class="form-group customerForm">
								<label class="col-sm-2 control-label">变更说明</label>
								<div class="col-sm-10">
                            <textarea class="form-control bg" id="stepComment" maxlength="120"
									  onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');" placeholder="120字以内"></textarea>
								</div>
							</div>
							<p class="default-buttons">
								<a href="javascript:void(0);" class="button-back btn btn-info" onclick="cleanCmt()">取消</a>
								<a href="javascript:void(0);" class="button-next  btn btn-info" onclick="addCmt()">提交</a>
							</p>
						</div>
					</section>

					<section class="panel">
						<header class="panel-heading">
							成本列表
						</header>
						<div class="panel-body">
							<div class="row">
								<div class="col-lg-3">
									<button class="btn btn-info m-bot15 tj">提交成本</button>
								</div>
							</div>
							<div id="clContainer" class="dlshouwen-grid-container"></div>
							<div id="clToolContainer" class="dlshouwen-grid-toolbar-container"></div>
						</div>
					</section>
					<section class="panel">
						<header class="panel-heading">
							历史记录
						</header>
						<div class="panel-body">
							<div class="row">
								<div class="col-lg-2">
									<div class="input-group m-bot15">
										<span class="input-group-addon" style="position: relative;z-index: 2;">年份</span>
										<select class="form-control"
											style="position: relative;margin-left:-4px;text-indent:2px;" id="pyear">
											<option value="0">请选择</option>
											<option value="2019">2019年</option>
											<option value="2020">2020年</option>
											<option value="2021">2021年</option>
											<option value="2022">2022年</option>
										</select>
									</div>
								</div>
								<div class="col-lg-2">
									<div class="input-group m-bot15">
										<span class="input-group-addon" style="position: relative;z-index: 2;">月份</span>
										<select class="form-control"
											style="position: relative;margin-left:-4px;text-indent:2px;" id="pmonth">
											<option value="0">请选择</option>
											<option value="1">1月</option>
											<option value="2">2月</option>
											<option value="3">3月</option>
											<option value="4">4月</option>
											<option value="5">5月</option>
											<option value="6">6月</option>
											<option value="7">7月</option>
											<option value="8">8月</option>
											<option value="9">9月</option>
											<option value="10">10月</option>
											<option value="11">11月</option>
											<option value="12">12月</option>
										</select>
									</div>
								</div>
								<div class="col-lg-3">
									<div class="input-group m-bot15">
										<span class="input-group-addon" style="position: relative;z-index: 2;">公司</span>
										<select class="form-control"
											style="position: relative;margin-left:-4px;text-indent:2px;" id="companyCode">
											<option value="" selected>全部</option>
											<!--<option value="HFKJ">浩方科技</option>-->
											<!--<option value="HFXX">浩方信息</option>-->
											<option value="STSBJ">赛特斯北京</option>
											<option value="STSGD">赛特斯广东</option>
											<!--<option value="STSJT">赛特斯集团</option>-->
											<option value="STSNJ">赛特斯南京</option>
											<option value="STSSH">赛特斯上海</option>
											<!--<option value="SYB-DL">电力事业部</option>-->
											<!--<option value="SYB-RX">融合运维事业部</option>-->
										</select>
									</div>
								</div>
								<div class="col-lg-3">
									<button class="btn btn-info searchhis m-bot15">搜索</button>
								</div>
							</div>
							<div id="cContainer" class="dlshouwen-grid-container"></div>
							<div id="cToolContainer" class="dlshouwen-grid-toolbar-container"></div>
						</div>
					</section>


					<section class="panel">
						<header class="panel-heading">
							工时成本计算步骤完成记录
						</header>
						<div class="panel-body">
							<div id="clHistryContainer" class="dlshouwen-grid-container"></div>
							<div id="clHistryToolContainer" class="dlshouwen-grid-toolbar-container"></div>
						</div>
					</section>
				</div>
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
					aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<section class="panel n-plt15" style="margin-bottom:0;">
								<div class="panel-heading add-heading">
									成本类型： {{costLevel}}
									<i class="add-icon icon-remove" data-dismiss="modal" aria-hidden="true"></i>
								</div>
								<div class="panel-body n-plt15" style="padding-bottom:0;">
									<div class="bio-row" style="width: 100%">
										<p>
											<span style="width: 50%">平均原成本（元/天）：</span>{{cost}}</p>
										<p>
											<span style="width: 50%">变更值（元/天）：</span>
											<span><input type="text" onkeyup="clearNoNum(this)" onblur="clearNoNum(this)" class="form-control"
													value="" id="bgCost" /></span></p>
										<p><button class="btn btn-info" id="qdCost">确定</button></p>
									</div>
								</div>
							</section>
						</div>
						<!-- /.modal-content -->
					</div>
					<!-- /.modal-dialog -->
				</div>

			</div>
		</section>
	</section>
	<!--main content end-->
</section>
<!-- 当前页面js文件引入 -->
<script type="text/javascript">

	function getServerDate() {
		//IE不兼容
		return new Date($.ajax({ type: 'HEAD', async: false }).getResponseHeader("Date"));
	}
    function cleanCmt() {
        $("#stepCmt").hide();
    }
	function findClList(CertusFormAjax, $scope) {
		var isCtj = true;
		var y1 = 0;
		var m1 = 0;
		this.canTj = function () {
			CertusFormAjax.ajax('findMaxTjTime', {}, function (result) {
				y1 = result.data.year;
				m1 = result.data.month;
				CertusFormAjax.ajax('findPreMonthStep3', { "year": y1, "month": m1 }, function (response) {
					if (!response.data) {
						$(".tj").attr("disabled", true);
						isCtj = false;
					} else {
						$(".tj").attr("disabled", false);
					}
					search(isCtj);
				});
			});
		};
		canTj();
		$(".tj").click(function () {
            $("#stepCmt").show();
		});
        this.addCmt = function () {
            layer.confirm('是否提交' + y1 + '年' + m1 + '月成本？提交后需要等待一分钟以便系统完成相关计算和归档。', {
                title: '提示信息',
                btn: ['是', '否'] //按钮
            }, function () {
                // 开启
                var index = layer.load(1);
                CertusFormAjax.ajax('addMonthStep3', { "year": y1, "month": m1,"comment":$("#stepComment").val() }, function () {
                    canTj();
                    $("#stepCmt").hide();
                    //关闭
                    layer.close(index);
                    layer.msg("提交成功！");
                });
            });
        };
		this.search = function (isCtj) {
			$("#clContainer").empty();
			$("#clToolContainer").empty();
			//成本列表
			var wpColumns = [{
				id: 'company',
				title: '归属公司',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'costLevel',
				title: '成本类型',
				type: 'string',
				columnClass: 'text-center',
				resolution: function (value, record) {
					var content = '';
					if (value == "KF-001") {
						content = '开发成本';
					} else if (value == "YF-001") {
						content = '用服成本';
					} else if (value == "OT-001") {
						content = '销管成本';
					} else if (value == "undefined") {
						content = '新入职员工';
					} else {
						content = '其他';
					}
					return content;
				}
			}, {
				id: 'cost',
				title: '成本(人天)',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'userName',
				title: '设定人员',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'createTime',
				title: '设定时间',
				type: 'string',
				columnClass: 'text-center',
			}, {
				id: 'status',
				title: '是否有效',
				type: 'string',
				columnClass: 'text-center',
				width: 70,
				resolution: function (value, record) {
					var content = '';
					if (value == 0) {
						content = '是';
					} else {
						content = '否';
					}
					return content;
				}
			}, {
				id: 'operation',
				title: '操作',
				width: 80,
				type: 'string',
				columnClass: 'text-center',
				resolution: function (value, record) {
					var content = '';
					if (isCtj) {
					    if (record.costLevel=="YF-001"){
                            content = '<button class="btn btn-xs btn-info" onclick="editCost(' + record.id + ');" data-toggle="modal" href="#myModal"><i class="fa fa-edit"></i>  编辑成本</button>';
                        }else{
                            content = '无';
						}
					} else {
						content = '无';
					}
					return content;
				}
			}];

			CertusFormAjax.ajax('findCostLevels', {
				"status": 0
			}, function (response) {
				var makingOption = {
					lang: 'zh-cn',
					ajaxLoad: false,
					extraWidth: 20,
					// loadURL:'url',
					exportFileName: '员工成本',
					datas: response.data,
					columns: wpColumns,
					gridContainer: 'clContainer',
					toolbarContainer: 'clToolContainer',
					tools: '',
					pageSize: 10,
					pageSizeLimit: [10, 15, 20]
				};
				var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
				makingGrid.load();
			});
		};

		this.editCost = function (id) {
			CertusFormAjax.ajax("findClById", { "id": id }, function (response) {
				var data = response.data;
                if (data.costLevel == "KF-001") {
                    $scope.costLevel = '开发成本修改';
                } else if (data.costLevel == "YF-001") {
                    $scope.costLevel = '用服成本修改';
                } else if (data.costLevel == "OT-001") {
                    $scope.costLevel = '销管成本修改';
                }
				$scope.cost = data.cost;
			});
			$scope.id = id;
		};

		$("#qdCost").click(function () {
			var bgCost = $("#bgCost").val();
			CertusFormAjax.ajax("editBgCost", { "id": $scope.id, "bgCost": bgCost }, function (response) {
				layer.msg("提交成功！");
				window.location.reload();
			});
		});

		//成本列表
        var clColumns = [{
            id: 'ltime',
            title: '月份',
            type: 'string',
            columnClass: 'text-center'
        },{
            id: 'step1UserName',
            title: '用服确认人',
            type: 'string',
            columnClass: 'text-center',
            width: 60
        }, {
            id: 'step1ConfirmTime',
            title: '用服确认时间',
            type: 'string',
            columnClass: 'text-center',
            width: 100
        }, {
            id: 'step1comment',
            title: '用服说明',
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'step2UserName',
            title: '开发确认人',
            type: 'string',
            columnClass: 'text-center',
            width: 60
        }, {
            id: 'step2ConfirmTime',
            title: '开发确认时间',
            type: 'string',
            columnClass: 'text-center',
            width: 100
        }, {
            id: 'step2comment',
            title: '开发说明',
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'step3UserName',
            title: '成本确认人',
            type: 'string',
            columnClass: 'text-center',
            width: 60
        }, {
            id: 'step3comment',
            title: '成本说明',
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'step3ConfirmTime',
            title: '成本确认时间',
            type: 'string',
            columnClass: 'text-center',
            width: 100
        }, {
            id: 'releaseTime',
            title: '成本计算时间',
            type: 'string',
            columnClass: 'text-center',
            width: 100
        }];

		CertusFormAjax.ajax('findCmcList', {
		}, function (response) {
			var makingOption = {
				lang: 'zh-cn',
				ajaxLoad: false,
				extraWidth: 20,
				// loadURL:'url',
				exportFileName: '员工成本',
				datas: response.data,
				columns: clColumns,
				gridContainer: 'clHistryContainer',
				toolbarContainer: 'clHistryToolContainer',
				tools: '',
				pageSize: 10,
				pageSizeLimit: [10, 15, 20]
			};
			var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
			makingGrid.load();
		});

		this.search2 = function () {
			$("#cContainer").empty();
			$("#cToolContainer").empty();
			//成本列表
			var wpColumns = [{
				id: 'company',
				title: '归属公司',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'yd',
				title: '日期',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'costLevel',
				title: '成本类型',
				type: 'string',
				columnClass: 'text-center',
				resolution: function (value, record) {
					var content = '';
					if (value == "KF-001") {
						content = '开发成本';
					} else if (value == "YF-001") {
						content = '用服成本';
					} else if (value == "OT-001") {
						content = '销管成本';
					} else if (value == "undefined") {
						content = '新入职员工';
					}
					return content;
				}
			}, {
				id: 'cost',
				title: '成本',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'userName',
				title: '设定人员',
				type: 'string',
				columnClass: 'text-center'
			}, {
				id: 'createTime',
				title: '设定时间',
				type: 'string',
				columnClass: 'text-center',
			}, {
				id: 'status',
				title: '是否有效',
				type: 'string',
				columnClass: 'text-center',
				width: 70,
				resolution: function (value, record) {
					var content = '';
					if (value == 0) {
						content = '是';
					} else {
						content = '否';
					}
					return content;
				}
			}];

			CertusFormAjax.ajax('findCostLevelsHis', {
				"year": $("#pyear").val(),
				"month": $("#pmonth").val(),
				"company": $("#companyCode").val()
			}, function (response) {
				var makingOption = {
					lang: 'zh-cn',
					ajaxLoad: false,
					extraWidth: 20,
					// loadURL:'url',
					exportFileName: '员工成本',
					datas: response.data,
					columns: wpColumns,
					gridContainer: 'cContainer',
					toolbarContainer: 'cToolContainer',
					tools: '',
					pageSize: 10,
					pageSizeLimit: [10, 15, 20]
				};
				var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
				makingGrid.load();
			});
		};
		search2();
		$(".searchhis").click(function () {
			search2();
		});
	}

</script>